/*
 * @Description:
 * @Date: 2023-02-16 17:16:58
 */
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import locale from 'element-plus/lib/locale/lang/zh-cn' // 中文语言
import './public-path.js'

import App from './App.vue'
import { router } from './router'

import './assets/main.css'

import { renderWithQiankun, qiankunWindow } from 'vite-plugin-qiankun/dist/helper'

let app = null
// 独立运行时
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  app = createApp(App)
  app.use(router('')) // router('')，独立运行，路由前缀为空
  app.use(ElementPlus, {
    locale: locale,
    size: 'default'
  })
  app.mount('#auth')
} else {
  // 作为微应用运行
  renderWithQiankun({
    // 调用renderWithQiankun
    mount(props) {
      console.log('auth mount')
      app = createApp(App)
      app.use(router(props._parent_base))
      app.use(ElementPlus, {
        locale: locale,
        size: 'default'
      })
      app.mount(props.container ? props.container.querySelector('#auth') : '#auth')
    },
    bootstrap() {
      // console.log("-- bootstrap --");
    },
    update() {
      // console.log("-- update --");
    },
    unmount() {
      // console.log("-- unmount --", app);
      app?.unmount()
    }
  })
}
